//
//  MamServer.m
//  HGMMRAC
//
//  Created by eport on 2021/1/19.
//

#import "MamServer.h"
#import <AFNetworking/AFNetworking.h>
#import "NSString+hui.h"

@implementation MamServer


+ (void)getPluginListWithPage:(int)page
                      Success: (void(^)(NSDictionary *resultDic)) success
                      failure:(void(^)(NSError *error))failure{


    
    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
    AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
    
    //
    NSURL *URL = [NSURL URLWithString:@"http://meam.mobile.customs.gov.cn:80/HGMAM/appInterface/getAllPlugin.do"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
        
    NSString *token = [[NSUserDefaults standardUserDefaults]objectForKey:@"token"];
    [request addValue: token forHTTPHeaderField:@"token"];
        
    [request setValue: @"hgmeap-mam" forHTTPHeaderField:@"Host"];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [request setHTTPMethod:@"POST"];
   // [request addValue: @"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [request addValue: @"charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    NSString*body=[NSString jsonStringWithDic:@{@"page":@(1),@"deptCode":@"海关总署\\总署机关\\中国电子口岸数据中心\\海关业务应用部",@"pageNum":@10,@"type":@1,@"hgflag":@"cgac"}];
    
    
    [request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
    NSString*msgLength=[NSString stringWithFormat:@"%ld",(unsigned long)[body length]];
    [request addValue:msgLength forHTTPHeaderField:@"Content-Length"];

   
    NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request uploadProgress:^(NSProgress * _Nonnull uploadProgress) {
        
    } downloadProgress:^(NSProgress * _Nonnull downloadProgress) {
        
    } completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
        
        if (responseObject) {
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
           
            success(dic);
        }else{
            failure(error);
        }
        
    }];
    

    [dataTask resume];
    
    
  
    
    
}


@end
